#ifndef SERIAL_PORT_HPP
#define SERIAL_PORT_HPP

#include <cstddef>

class SerialPort {
public:
    enum class Parity {
        None,
        Odd,
        Even,
    };

    enum class StopBits : unsigned int {
        One = 1,
        Two = 2,
    };

    enum class FlowControl : unsigned int {
        None = 0,
        CTS = 1,
        RTS = 2,
        CTSAndRTS = 3,
    };

    enum class Event : unsigned int {
        WriteComplete,
        ReadComplete,
        DataReceived,
        Idle,
        ErrorOccurred,
    };

public:
    virtual ~SerialPort() = default;

    virtual bool open(void) = 0;
    virtual bool close(void) = 0;
    virtual size_t read(void *buffer,size_t size) = 0;
    virtual size_t write(const void *buffer,size_t size) = 0;

    virtual bool setBaudrate(unsigned int baudrate) = 0;
    virtual unsigned int getBaudrate(void) = 0;
    virtual bool setDataBits(unsigned int data_bits) = 0;
    virtual unsigned int getDataBits(void) = 0;
    virtual bool setParity(Parity parity) = 0;
    virtual Parity getParity(void) = 0;
    virtual bool setStopBits(StopBits stop_bits) = 0;
    virtual StopBits getStopBits(void) = 0;
    virtual bool setFlowControl(FlowControl flow_control) = 0;
    virtual FlowControl getFlowControl(void) = 0;

    virtual bool addEventCallback(Event event,void (*callback)(void)) = 0;
    virtual bool removeEventCallback(Event event) = 0;

    virtual int getErrorNumber(void) = 0;
};

#endif
